package csu.web.mypetstore.web.servlet;

import csu.web.mypetstore.domain.Account;
import csu.web.mypetstore.service.LogService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SignOffFormServlet extends HttpServlet {

    private static final String SIGNOFF_FORM = "/WEB-INF/jsp/account/signoff.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();

        Account account=(Account) session.getAttribute("loginAccount");
        LogService logService = new LogService();
        String logInfo = logService.logInfo(" ") +"用户" +account.getUsername()+  "  " +"登出";
        logService.insertLogInfo(account.getUsername(),logInfo);
        session.setAttribute("loginAccount",null);

        //req.setAttribute("loginAccount", account);

        req.getRequestDispatcher(SIGNOFF_FORM).forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
